// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import vuescroll from 'vuescroll'
import i18n from './i18n' // 语言包
import routes from './premission'
import { api } from './api'
import Fragment from 'vue-fragment'
import Nprogress from 'nprogress'
import store from './store'
import './components/basics'
import 'nprogress/nprogress.css'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI, { size: 'big', zIndex: 3000 })
Vue.use(vuescroll)
Vue.use(Fragment.Plugin)

Vue.prototype.$api = api
router.beforeEach((to, from, next) => {
  Nprogress.start()
  if (to.path === '/login') {
    window.sessionStorage.removeItem('lbtk')
    window.sessionStorage.removeItem('ms_username')
    next()
  } else if (!store.getters.isAuth) {
    store.dispatch('getUserPromission', {
      to,
      next,
      routes
    })
  } else {
    if (from.meta.refresh) {
      to.meta.refresh = true
      from.meta.refresh = false
    }
    next()
  }
})
router.afterEach(() => {
  Nprogress.done()
})

Vue.config.productionTip = false

/* eslint-disable no-new */
let vue = new Vue({
  el: '#app',
  router,
  i18n,
  components: { App },
  template: '<App/>'
})
export default vue
